<%--
  Created by IntelliJ IDEA.
  User: tangyunyuan
  Date: 2021/4/26
  Time: 19:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.gson.Gson" %>
<html>
<script src="jsgol/jQuery.js"></script>
<head>
    <title>薪资管理</title>
</head>
<body>
<%
    if (session.getAttribute("msg") != null) {
        out.print("<script> alert('" + session.getAttribute("msg") + "'); </script>");
        session.removeAttribute("msg");
    }
%>
<%@include file="Canvas.jsp" %>
<div style="width:800px;height: 700px;border: gray solid 1px;margin:0 auto;background: beige;margin-top: 7%;">
    <%@include file="header.jsp" %>
    <div class="botton" style="width:100%;height:430px;border: red solid 1px;margin: 0px auto;position: relative;">
        <div style="text-align: center">
            <button type="submit">年月查询</button>
            <input type="text" placeholder="请输入日期/姓名" name="xxx">
            <button type="submit">员工查询</button>
            <select name="education" onchange="document.getElementById('search').sumbit()">
                <%
                    String education = request.getParameter("education");
                    if (education == null) {
                        education = "所有";
                    }
                %>
                <option value="所有" <%= education.equals("所有") ? "selected" : ""%>>所有</option>
                <option value="本科生" <%= education.equals("本科生") ? "selected" : ""%>>本科生</option>
                <option value="研究生" <%= education.equals("研究生") ? "selected" : ""%>>研究生</option>
            </select>
        </div>

        <table id="tableData" border="1" style="width: 100%; text-align: center">

        </table>
        <div style="position: absolute;bottom: -50px;">
            <img src="idemge/down.jpg" alt="">
        </div>
        <div style="float: right;font-weight: bold">
            <%
                // 用户总数，用于判断分多少页
                Long userLen = (Long) session.getAttribute("userLen");
                if (userLen != null) {
                    for (int i = 0; i < userLen / 10 + 1; i++) {
                        out.print("<a href='" + request.getContextPath() + "/salist?page=" + (i + 1) + "'>" + (i + 1) + "</a>");
                    }
                    out.print("共" + (userLen / 10 + 1) + "页");
                }
            %>
        </div>
        <a href="<%=request.getContextPath()%>/Addsalary.jsp"
           style="position: absolute;bottom: 40px;right: 15px;">添加薪资</a>
    </div>
</div>
</body>
<script type="text/javascript" src="jsgol/protect.js"></script>
<script>
    var salary = JSON.parse('<%= new Gson().toJson(session.getAttribute("salarylist"))%>');
    console.log(salary);

    function createTable() {
        var data = $('#tableData');
        data.html(`<tr><th>员工编号</th><th>员工姓名</th><th>当前月份</th><th>基本工资</th><th>加班费</th><th>工龄费</th><th>考勤费</th><th>旷工费</th><th>保险费</th><th>实发工资</th><th>操作</th></tr>`)
        for (let i = 0; i < salary.length; i++) {
            data.append(`<tr>
                        <td>${salary[i].X_id ? salary[i].X_id : '无'}</td>
                        <td>${salary[i].X_name ? salary[i].X_name : '无'}</td>
                        <td>${salary[i].X_month ? salary[i].X_month : '无'}</td>
                        <td>${salary[i].X_basepay ? salary[i].X_basepay : '无'}</td>
                        <td>${salary[i].X_overtimepay ? salary[i].X_overtimepay : '无'}</td>
                        <td>${salary[i].X_expenses ? salary[i].X_expenses : '无'}</td>
                        <td>${salary[i].X_attendance ? salary[i].X_attendance : '无'}</td>
                        <td>${salary[i].X_absenteeism ? salary[i].X_absenteeism : '无'}</td>
                        <td>${salary[i].X_insurance ? salary[i].X_insurance : '无'}</td>
                        <td>${salary[i].X_wages ? salary[i].X_wages : '无'}</td>
                         <td><button onclick="dele(${i})">删除</button></td>
             </tr>`);

        }
    }

    function dele(index) {
        var sqe = confirm("确定要删除吗?");
        if (sqe == true) {
            location.href = 'sadele?dele=' + salary[index].X_id;
        }
    }

    createTable();
    $('#navMore').html('> 薪资查询');
</script>


<style>
    .botton {
        background: url(idemge/6.png) no-repeat;
        background-size: 100% 100%;
    }
</style>


</html>
